
package com.idealighter.game.games.happyfive.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.gamehall.dto.SeatInfo;
import com.idealighter.game.games.happyfive.HappyFivePlayer;
import com.idealighter.game.games.happyfive.message.ReqCheckCardMsg;
import com.idealighter.game.games.happyfive.message.ResNextSeatMsg;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;
import com.idealighter.utils.code.RandCodeUtil;

import java.util.concurrent.TimeUnit;


@ResMsgHandler(507220)
public class ResNextSeatHandler implements ResMessageHandler {
  // private static final Logger LOG = LoggerFactory.getLogger(ResNextSeatHandler.class);

  @Override
  public void action(Player player, ResMessage message) {
    ResNextSeatMsg msg = (ResNextSeatMsg) message;
    HappyFivePlayer happyFivePlayer = (HappyFivePlayer) player;
    SeatInfo seatInfo = happyFivePlayer.seat(player.playerId);
    if (seatInfo != null && seatInfo.getOrder() == msg.getOrder()) {
      happyFivePlayer.betDesision(msg.getCurMaxBet(), msg.getAllInBet());
      int time = RandCodeUtil.random(happyFivePlayer.domain.getTimeMin(),
          happyFivePlayer.domain.getTimeMax());
      // if (time == 0) {
      // time = RandCodeUtil.random(3, 6);
      // }
      // time = 3;
      if (RandCodeUtil.randomBoolean()) {
        // 下注前随机看牌
        player.sendMsg(new ReqCheckCardMsg());
      }
      player.schedule(() -> happyFivePlayer.sendBetInfo(), time, TimeUnit.SECONDS);
    }
  }
}
